
#include "bus_capacitor.h"

bus_capacitor::bus_capacitor():capacitor(0,0,0)
{
}

void bus_capacitor::set_min_work_vol(double v)
{
    if (v <= 0)
    {
        return;
    }

    min_voltage = v;
}

void bus_capacitor::set_max_power(double w)
{
    if (w <= 0)
    {
        return;
    }

    max_power = w;
}

void bus_capacitor::set_efficency(double n)
{
    if (n <= 0)
    {
        return;
    }

    efficiency = n;
}

void bus_capacitor::set_work_freq(unsigned int hz)
{
    if (hz <= 0)
    {
        return;
    }

    work_frequency = hz;
}

void bus_capacitor::set_ripple_voltage(double v)
{
    if (v <= 0)
    {
        return;
    }

    ripple_voltage = v;
}






/**
 * @brief   根据控制器的参数计算母线电容的最小值
 */
double bus_capacitor::calculate_min_cap_value()
{
    double cap = max_power/(work_frequency * efficiency * min_voltage * ripple_voltage);
    return cap;
}

/**
 * @brief   核对输入的电容参数是否满足要求
 * @param   t - 工作温度（℃）
 * @parma   h - 工作时间（h）
 * @retval  电容输出能量占需要能量的比值
 */
double bus_capacitor::wcca(double t, double h)
{

    // 释放能量
    double e_out = get_min_value(t, h) * min_voltage * ripple_voltage;

    // 计算占比
    double e_need = max_power / (work_frequency * efficiency);

    return e_out / e_need;

}

double bus_capacitor::calculate_ripple_voltage_current()
{
    return 0;
}




